home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0179.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  1.8 KB  |  62 lines

  1. On 16 Mar 98 07:44:05 GMT, "Jonas Thorell"
  2. <jonasth@RemoveThisPart.bahnhof.se> wrote:
  3.  
  4. >Okay, see if someone can help me out here. What I want is to take an ordinary
  5. >textfile and process in certain ways. What I need to do is to
  6. >
  7. >1. Determine how many lines of text it is in it. How?
  8. >2. Use the above value making a for-loop like
  9. >
  10. >For a=1 to <the value mentioned>
  11. >    grab one line of text and insert it in t$(a)
  12. >next 
  13. >
  14. >I've tried with input # and line input # but they seem to want to grab the whole
  15. >text in one chunk.
  16.  
  17. I am almost sure that your problem is caused by the fact that AMOS
  18. doesn't see lines the way the OS sees them. AmigaOS (as Unix) thinks a
  19. line is something terminated by a linefeed. AMOS on the other hand
  20. sees lines the MS-DOS way: terminated by a carriage return and then a
  21. linefeed (I am not entirely sure that is the correct order, though).
  22.  
  23. I believe AMOS has a way of actually setting what the EOL character
  24. sequence should be. I have never used it, though. I am not sure wether
  25. this is because the implementation is buggy or because it only works
  26. one way (writing?). I have always preferred scanning for lines my
  27. self:
  28.  
  29. global count
  30. count = 0
  31. name$=fsel$("")
  32. open in 1, name$
  33. lf=lof(1)
  34. buffer = 1024
  35. repeat
  36.   if buffer < lf then buffer = lf
  37.   a$=input$(1,buffer)
  38.   scan[a$,buffer]
  39. until buffer<=0
  40. print "number of lines:"; count
  41.  
  42. procedure count[a$,b]
  43.   for i=1 to b
  44.     if mid$(a$,i,1)=chr$(10) then inc count
  45.   next i
  46. end proc
  47.  
  48. Undoubtedly I have omitted a few things or made a few mistakes, but
  49. this is roughly how it works.
  50.  
  51. -- 
  52. branko collin
  53. --
  54. Brought to you from the AMOS Mailinglist!!
  55.  
  56. mailto: amos-request@access.digex.net  Subject: SUBSCRIBE <Email Address>
  57.  
  58. Posted via Mailinglist Manager V2.10, available soon from
  59. http://www.mushy-pd.demon.co.uk - the worlds largest AMOS homepages
  60. Email me at mushypd@redrose.net for more information!
  61.  
  62.